import { BaseGraph, IBaseProps, IBoundBox } from './base'

let index = 0
export interface IRectProps extends IBaseProps {
  width?: number
  height?: number
}

/**
 * 圆形
 */
export class Rect extends BaseGraph {
  public width: number = 100
  public height: number = 100
  public uuid: number = 0
  constructor(props?: IRectProps) {
    super(props)
    this.type = 'rect'
    this.uuid = index++
    this.width = props?.width || this.width
    this.height = props?.height || this.height
    this.setPath()
  }
  public setPath() {
    delete this.path
    this.path = new Path2D()
    this.path.rect(0, 0, this.width, this.height)
  }
  public drawPath(ctx: CanvasRenderingContext2D): void {
    if (this.isFill) ctx.fill(this.path)
    else ctx.stroke(this.path)
  }
  public clone() {
    return new Rect({ ...this.option, ...this.getBaseCloneAttr(), width: this.width, height: this.height })
  }
  public getBoundBox(): IBoundBox {
    return {
      top: this.y,
      bottom: this.y + this.height,
      left: this.x,
      right: this.x + this.width,
      width: this.width,
      height: this.height
    }
  }
}
